<?php

class Model_HmNewsComments extends Zend_Db_Table_Abstract
{
	protected $_name = 'hm_news_comments';
	protected $_primary = 'id';
	
	public function getAll($id)
	{
		$query = $this->select()->where('hm_news_id = '.(int)$id);
		$row = $this->fetchAll($query);
		if(!$row) {
			throw new Exception('Could not fetch records.');
		}
		return $row->toArray();
	}
	
	public function addRow($data)
	{
		$row = $this->createRow($data);
		$row->save();
	}
	
	public function deleteRow($comment_id, $id)
	{
		$where = 'id = '.(int)$comment_id.' AND hm_news_id = '.(int)$id;
		$row = $this->delete($where);
		if(!$row) {
			throw new Exception('Could not delete row '.(int)$comment_id);
		}
		return true;
	}
}